home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / jDictionary 1.8 / jdictionary-1_8-win.exe / src-1_8 / info / jdictionary / Preferences.java < prev    next >
Encoding:
Java Source  |  2002-08-11  |  25.0 KB  |  697 lines

  1. /*
  2.  * 01/09/2002 - 20:43:57
  3.  *
  4.  * Preferences.java -
  5.  * Copyright (C) 2002 Csaba KertΘsz
  6.  * kcsaba@jdictionary.info
  7.  * www.jdictionary.info
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU Lesser General Public License
  11.  * as published by the Free Software Foundatin; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU Lesser General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU Lesser General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24.  
  25. package info.jdictionary;
  26.  
  27. import org.apache.regexp.RE;
  28. import javax.swing.JPanel;
  29. import javax.swing.JScrollPane;
  30. import javax.swing.BoxLayout;
  31. import javax.swing.JLabel;
  32. import javax.swing.JCheckBox;
  33. import javax.swing.JTextField;
  34. import javax.swing.JButton;
  35. import javax.swing.JPasswordField;
  36. import javax.swing.JComboBox;
  37. import java.awt.Color;
  38. import java.awt.Dimension;
  39. import javax.swing.BorderFactory;
  40. import java.awt.event.ActionEvent;
  41. import java.awt.event.ActionListener;
  42. import java.awt.event.KeyEvent;
  43. import javax.swing.event.ChangeEvent;
  44. import javax.swing.event.ChangeListener;
  45. import info.jdictionary.events.PluginSelectionEvent;
  46. import info.jdictionary.listeners.PluginSelectionListener;
  47.  
  48. public class Preferences extends JPanel {
  49.  
  50.     private JDictionary jDictionary;
  51.     private Prefs prefs;
  52.     private boolean changesSaved = false;
  53.     private JButton applyButton;
  54.     private JPanel output;
  55.     private JScrollPane outputScrollPane;
  56.  
  57.     private JTextField serverTextField;
  58.     private JTextField portTextField;
  59.     private JTextField loginTextField;
  60.     private JPasswordField passwordField;
  61.  
  62.     private JCheckBox upgradeCheckBox;
  63.     private JCheckBox newsCheckBox;
  64.     private JCheckBox proxyCheckBox;
  65.     private JCheckBox authCheckBox;
  66.  
  67.     private JComboBox typeComboBox = new JComboBox();
  68.     private String httpType = new String("HTTP Type");
  69.     private String socksType = new String("SOCKS Proxy");
  70.     private String shownType;
  71.  
  72.     boolean usingHttpProxy;
  73.     boolean usingSocksProxy;
  74.     boolean usingHttpProxyLogin;
  75.     boolean usingSocksProxyLogin;
  76.     String socksServer;
  77.     String socksPort;
  78.     String socksLogin;
  79.     char[] socksPassword;
  80.     String httpServer;
  81.     String httpPort;
  82.     String httpLogin;
  83.     char[] httpPassword;
  84.  
  85.     private JLabel portLabel;
  86.     private JLabel serverLabel;
  87.     private JLabel typeLabel;
  88.     private JLabel loginLabel;
  89.     private JLabel passwordLabel;
  90.  
  91.     private Color highLightColor = Color.orange;
  92.  
  93.     public Preferences(JDictionary jDictionary) {
  94.         super();
  95.         this.jDictionary = jDictionary;
  96.         this.prefs = jDictionary.getPrefs();
  97.         //jDictionary.getPluginManager().addPluginSelectionListener(new PluginSelectionListener() {
  98.         //    public void pluginSelected(PluginSelectionEvent e) {
  99.         //        pluginManager_pluginSelected(e);
  100.         //    }
  101.         //});
  102.  
  103.         socksServer = new String(prefs.socksProxyServer);
  104.         socksPort = new String(prefs.socksProxyPort);
  105.         socksLogin = new String(prefs.socksProxyLogin);
  106.         socksPassword = new String(prefs.socksProxyPassword).toCharArray();
  107.         httpServer = new String(prefs.httpProxyServer);
  108.         httpPort = new String(prefs.httpProxyPort);
  109.         httpLogin = new String(prefs.httpProxyLogin);
  110.         httpPassword = new String(prefs.httpProxyPassword).toCharArray();
  111.         usingHttpProxy = prefs.usingHttpProxy;
  112.         usingSocksProxy = prefs.usingSocksProxy;
  113.         usingHttpProxyLogin = prefs.usingHttpProxyLogin;
  114.         usingSocksProxyLogin = prefs.usingSocksProxyLogin;
  115.  
  116.         setBackground(Color.white);
  117.         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  118.         setMinimumSize(new Dimension(400, 300));
  119.         setPreferredSize(new Dimension(400, 300));
  120.  
  121.         JLabel header = new JLabel();
  122.         header = new JLabel(ImageBank.getImageByName("PreferencesHeader.png"));
  123.         header.setAlignmentX((float) 0.0);
  124.         header.setMinimumSize(new Dimension(300, 65));
  125.         header.setPreferredSize(new Dimension(500, 65));
  126.         header.setBackground(Color.white);
  127.  
  128.         if(this.usingSocksProxy)
  129.                    shownType = socksType;
  130.                    else
  131.                    shownType = httpType;
  132.  
  133.         //setting up network section///////////////////////////////////////////
  134.         serverTextField = new JTextField();
  135.         serverTextField.setMaximumSize(new Dimension(200, 22));
  136.         serverTextField.setPreferredSize(new Dimension(200, 22));
  137.         serverTextField.addKeyListener(new java.awt.event.KeyAdapter() {
  138.             public void keyTyped(KeyEvent e) {
  139.                 serverTextField_keyTyped(e);
  140.             }
  141.         });
  142.  
  143.         portTextField = new JTextField();
  144.         portTextField.setMaximumSize(new Dimension(200, 22));
  145.         portTextField.setPreferredSize(new Dimension(200, 22));
  146.         portTextField.addKeyListener(new java.awt.event.KeyAdapter() {
  147.                     public void keyTyped(KeyEvent e) {
  148.                         portTextField_keyTyped(e);
  149.                     }
  150.         });
  151.  
  152.         loginTextField = new JTextField();
  153.         loginTextField.setMaximumSize(new Dimension(200, 22));
  154.         loginTextField.setPreferredSize(new Dimension(200, 22));
  155.         loginTextField.addKeyListener(new java.awt.event.KeyAdapter() {
  156.                     public void keyTyped(KeyEvent e) {
  157.                         loginTextField_keyTyped(e);
  158.                     }
  159.         });
  160.  
  161.         passwordField = new JPasswordField();
  162.         passwordField.setMaximumSize(new Dimension(200, 22));
  163.         passwordField.setPreferredSize(new Dimension(200, 22));
  164.         passwordField.addKeyListener(new java.awt.event.KeyAdapter() {
  165.             public void keyTyped(KeyEvent e) {
  166.                 passwordField_keyTyped(e);
  167.             }
  168.         });
  169.  
  170.         proxyCheckBox = new JCheckBox(JDictionary.getString("IUseProxy"));
  171.         proxyCheckBox.setAlignmentX((float)0.0);
  172.         proxyCheckBox.setBackground(Color.white);
  173.         proxyCheckBox.setSelected(usingHttpProxy || usingSocksProxy);
  174.         proxyCheckBox.addChangeListener(new ChangeListener() {
  175.             public void stateChanged(ChangeEvent e) {
  176.                 proxyCheckBox_stateChanged(e);
  177.             }
  178.         });
  179.  
  180.         authCheckBox = new JCheckBox(JDictionary.getString("LoginToProxy"));
  181.         authCheckBox.setBackground(Color.white);
  182.         authCheckBox.addChangeListener(new ChangeListener() {
  183.                     public void stateChanged(ChangeEvent e) {
  184.                         authCheckBox_stateChanged(e);
  185.                     }
  186.         });
  187.         typeComboBox.setMaximumSize(new Dimension(200, 24));
  188.         typeComboBox.setPreferredSize(new Dimension(200, 24));
  189.         typeComboBox.setBackground(Color.white);
  190.         typeComboBox.addItem(httpType);
  191.         typeComboBox.addItem(socksType);
  192.         if(usingHttpProxy)
  193.             typeComboBox.setSelectedItem(httpType);
  194.         if(usingSocksProxy)
  195.             typeComboBox.setSelectedItem(socksType);
  196.         typeComboBox.addActionListener(new ActionListener() {
  197.             public void actionPerformed(ActionEvent e) {
  198.                 typeComboBox_actionPerformed(e);
  199.             }
  200.         });
  201.  
  202.         JPanel networkPanel = new JPanel();
  203.         networkPanel.setBackground(Color.white);
  204.         networkPanel.setLayout(new BoxLayout(networkPanel, BoxLayout.X_AXIS));
  205.         networkPanel.setBorder(BorderFactory.createTitledBorder(JDictionary.getString("ConnectPrefs")));
  206.  
  207.         JLabel networkLabel = new JLabel();
  208.         networkLabel.setAlignmentY(0);
  209.         networkLabel = new JLabel(IconBank.getIconByName("NetworkBig.png"));
  210.  
  211.         JPanel networkIconPanel = new JPanel();
  212.         networkIconPanel.setBackground(Color.white);
  213.         networkIconPanel.setAlignmentY(0);
  214.         networkIconPanel.add(networkLabel);
  215.         networkIconPanel.setMaximumSize(new Dimension(64, 64));
  216.  
  217.         JPanel proxyPanel = new JPanel();
  218.         proxyPanel.setBackground(Color.white);
  219.         proxyPanel.setAlignmentY(0);
  220.         proxyPanel.setLayout(new BoxLayout(proxyPanel, BoxLayout.Y_AXIS));
  221.         proxyPanel.add(proxyCheckBox);
  222.         proxyPanel.add(typeComboBox);
  223.         proxyPanel.setMaximumSize(new Dimension(380, 160));
  224.         proxyPanel.setPreferredSize(new Dimension(300, 160));
  225.  
  226.         JPanel typePanel = new JPanel();
  227.         typePanel.setAlignmentX((float)0.0);
  228.         typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.X_AXIS));
  229.         typePanel.setBackground(Color.white);
  230.         typeLabel = new JLabel(JDictionary.getString("ProxyType"));
  231.         typePanel.add(typeLabel);
  232.         JPanel typeSpacer = new JPanel();
  233.         typeSpacer.setBackground(Color.white);
  234.         typePanel.add(typeSpacer);
  235.         typePanel.add(typeComboBox);
  236.         proxyPanel.add(typePanel);
  237.  
  238.         JPanel serverPanel = new JPanel();
  239.         serverPanel.setBackground(Color.white);
  240.         serverPanel.setAlignmentX((float)0.0);
  241.         serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.X_AXIS));
  242.         serverLabel = new JLabel(JDictionary.getString("ProxyServer"));
  243.         serverPanel.add(serverLabel);
  244.         JPanel serverSpacer = new JPanel();
  245.         serverSpacer.setBackground(Color.white);
  246.         serverPanel.add(serverSpacer);
  247.         serverPanel.add(serverTextField);
  248.         proxyPanel.add(serverPanel);
  249.  
  250.         JPanel portPanel = new JPanel();
  251.         portPanel.setBackground(Color.white);
  252.         portPanel.setAlignmentX((float)0.0);
  253.         portPanel.setLayout(new BoxLayout(portPanel, BoxLayout.X_AXIS));
  254.         portLabel = new JLabel(JDictionary.getString("ProxyPort"));
  255.         portPanel.add(portLabel);
  256.         JPanel portSpacer = new JPanel();
  257.         portSpacer.setBackground(Color.white);
  258.         portPanel.add(portSpacer);
  259.         portPanel.add(portTextField);
  260.         proxyPanel.add(portPanel);
  261.  
  262.         proxyPanel.add(authCheckBox);
  263.  
  264.         JPanel loginPanel = new JPanel();
  265.         loginPanel.setBackground(Color.white);
  266.         loginPanel.setAlignmentX((float)0.0);
  267.         loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.X_AXIS));
  268.         loginLabel = new JLabel(JDictionary.getString("ProxyLogin"));
  269.         loginPanel.add(loginLabel);
  270.         JPanel loginSpacer = new JPanel();
  271.         loginSpacer.setBackground(Color.white);
  272.         loginPanel.add(loginSpacer);
  273.         loginPanel.add(loginTextField);
  274.         proxyPanel.add(loginPanel);
  275.  
  276.         JPanel passwordPanel = new JPanel();
  277.         passwordPanel.setBackground(Color.white);
  278.         passwordPanel.setLayout(new BoxLayout(passwordPanel, BoxLayout.X_AXIS));
  279.         passwordLabel = new JLabel(JDictionary.getString("ProxyPassword"));
  280.         passwordPanel.add(passwordLabel);
  281.         JPanel passwordSpacer = new JPanel();
  282.         passwordSpacer.setBackground(Color.white);
  283.         passwordPanel.add(passwordSpacer);
  284.         passwordPanel.add(passwordField);
  285.         passwordPanel.setAlignmentX((float)0.0);
  286.         proxyPanel.add(passwordPanel);
  287.  
  288.         networkPanel.add(networkIconPanel);
  289.         JPanel networkSpacer = new JPanel();
  290.         networkSpacer.setMaximumSize(new Dimension(30, 30));
  291.         networkSpacer.setBackground(Color.white);
  292.         networkPanel.add(networkSpacer);
  293.         networkPanel.add(proxyPanel);
  294.         //end of network section setup
  295.  
  296.  
  297.         //setting up startup section
  298.         JPanel startupPanel = new JPanel();
  299.         startupPanel.setBackground(Color.white);
  300.         startupPanel.setLayout(new BoxLayout(startupPanel, BoxLayout.X_AXIS));
  301.         startupPanel.setBorder(BorderFactory.createTitledBorder(JDictionary.getString("StartupPrefs")));
  302.  
  303.         JLabel startupLabel = new JLabel();
  304.         startupLabel = new JLabel(IconBank.getIconByName("Download.png"));
  305.         startupLabel.setAlignmentY(0);
  306.  
  307.         JPanel startupIconPanel = new JPanel();
  308.         startupIconPanel.setBackground(Color.white);
  309.         startupIconPanel.add(startupLabel);
  310.         startupIconPanel.setMaximumSize(new Dimension(64, 64));
  311.         startupIconPanel.setAlignmentY(0);
  312.  
  313.  
  314.         upgradeCheckBox = new JCheckBox(JDictionary.getString("CheckForUpgrades"));
  315.         upgradeCheckBox.setBackground(Color.white);
  316.         upgradeCheckBox.addActionListener(new ActionListener() {
  317.             public void actionPerformed(ActionEvent e) {
  318.                 upgradeCheckBox_actionPerformed(e);
  319.             }
  320.         });
  321.  
  322.         newsCheckBox = new JCheckBox(JDictionary.getString("CheckForNews"));
  323.         newsCheckBox.setBackground(Color.white);
  324.         newsCheckBox.addActionListener(new ActionListener() {
  325.             public void actionPerformed(ActionEvent e) {
  326.                 newsCheckBox_actionPerformed(e);
  327.             }
  328.         });
  329.  
  330.         JPanel startupSettingsPanel = new JPanel();
  331.         startupSettingsPanel.setBackground(Color.white);
  332.         startupSettingsPanel.setAlignmentY(0);
  333.         startupSettingsPanel.setLayout(new BoxLayout(startupSettingsPanel, BoxLayout.Y_AXIS));
  334.         startupSettingsPanel.add(upgradeCheckBox);
  335.         startupSettingsPanel.add(newsCheckBox);
  336.         startupSettingsPanel.setMaximumSize(new Dimension(380, 60));
  337.         startupSettingsPanel.setPreferredSize(new Dimension(300, 60));
  338.  
  339.         startupPanel.add(startupIconPanel);
  340.         JPanel startupSpacer = new JPanel();
  341.         startupSpacer.setMaximumSize(new Dimension(30, 30));
  342.         startupSpacer.setBackground(Color.white);
  343.         startupPanel.add(startupSpacer);
  344.         startupPanel.add(startupSettingsPanel);
  345.         //end of startup section setup
  346.  
  347.  
  348.         applyButton = new JButton(JDictionary.getString("ApplyButton"));
  349.         applyButton.setAlignmentX((float)0.5);
  350.         applyButton.setIcon(IconBank.getIconByName("Check.png"));
  351.         applyButton.setEnabled(false);
  352.         applyButton.addActionListener(new ActionListener() {
  353.             public void actionPerformed(ActionEvent e) {
  354.                 applyButton_actionPerformed(e);
  355.             }
  356.         });
  357.  
  358.         output = new JPanel();
  359.         output.setBackground(Color.white);
  360.         output.setLayout(new BoxLayout(output, BoxLayout.Y_AXIS));
  361.         output.setAlignmentX((float)0.0);
  362.         JPanel outputSpacer1 = new JPanel();
  363.         outputSpacer1.setBackground(Color.white);
  364.         output.add(outputSpacer1);
  365.         output.add(networkPanel);
  366.         JPanel outputSpacer2 = new JPanel();
  367.         outputSpacer2.setBackground(Color.white);
  368.         output.add(outputSpacer2);
  369.         output.add(startupPanel);
  370.         JPanel outputSpacer3 = new JPanel();
  371.         outputSpacer3.setBackground(Color.white);
  372.         output.add(outputSpacer3);
  373.         output.add(applyButton);
  374.         JPanel outputSpacer4 = new JPanel();
  375.         outputSpacer3.setBackground(Color.white);
  376.         output.add(outputSpacer3);
  377.  
  378.         outputScrollPane = new JScrollPane();
  379.         outputScrollPane.getViewport().add(output);
  380.  
  381.         add(header);
  382.         add(outputScrollPane);
  383.  
  384.         updateNetworkSection();
  385.         fillupNetworkTextFields();
  386.         updateStartupSection();
  387.     }
  388.  
  389.  
  390.     void proxyCheckBox_stateChanged(ChangeEvent e) {
  391.         changesSaved = false;
  392.         checkApplyButtonStatus();
  393.         updateNetworkSection();
  394.     }
  395.  
  396.  
  397.     void authCheckBox_stateChanged(ChangeEvent e) {
  398.         changesSaved = false;
  399.         checkApplyButtonStatus();
  400.         if(authCheckBox.isSelected()) {
  401.             if(typeComboBox.getSelectedItem().equals(httpType))
  402.                 usingHttpProxyLogin = true;
  403.             if(typeComboBox.getSelectedItem().equals(socksType))
  404.                 usingSocksProxyLogin = true;
  405.         }
  406.         else {
  407.             if(typeComboBox.getSelectedItem().equals(httpType))
  408.                 usingHttpProxyLogin = false;
  409.             if(typeComboBox.getSelectedItem().equals(socksType))
  410.                 usingSocksProxyLogin = false;
  411.         }
  412.         updateNetworkSection();
  413.     }
  414.  
  415.  
  416.     void typeComboBox_actionPerformed(ActionEvent e) {
  417.         changesSaved = false;
  418.         checkApplyButtonStatus();
  419.         updateNetworkSection();
  420.         updateNetworkSectionTextFields();
  421.     }
  422.  
  423.  
  424.     void serverTextField_keyTyped(KeyEvent e) {
  425.            changesSaved = false;
  426.            checkApplyButtonStatus();
  427.        }
  428.  
  429.  
  430.     void portTextField_keyTyped(KeyEvent e) {
  431.         changesSaved = false;
  432.         checkApplyButtonStatus();
  433.     }
  434.  
  435.  
  436.     void loginTextField_keyTyped(KeyEvent e) {
  437.         changesSaved = false;
  438.         checkApplyButtonStatus();
  439.     }
  440.  
  441.  
  442.     void passwordField_keyTyped(KeyEvent e) {
  443.         changesSaved = false;
  444.         checkApplyButtonStatus();
  445.     }
  446.  
  447.  
  448.     void upgradeCheckBox_actionPerformed(ActionEvent e) {
  449.         changesSaved = false;
  450.         checkApplyButtonStatus();
  451.         if(((JCheckBox)e.getSource()).isSelected())
  452.             prefs.CheckingForUpgrade = true;
  453.         else
  454.             prefs.CheckingForUpgrade = false;
  455.         updateStartupSection();
  456.     }
  457.  
  458.  
  459.     void newsCheckBox_actionPerformed(ActionEvent e) {
  460.         changesSaved = false;
  461.         checkApplyButtonStatus();
  462.         if(((JCheckBox)e.getSource()).isSelected())
  463.             prefs.CheckingForNews = true;
  464.         else
  465.             prefs.CheckingForNews = false;
  466.         updateStartupSection();
  467.     }
  468.  
  469.     void checkApplyButtonStatus() {
  470.         if(!changesSaved)
  471.             applyButton.setEnabled(true);
  472.     }
  473.  
  474.  
  475.     void applyButton_actionPerformed(ActionEvent e) {
  476.         if(savePrefs()) {
  477.             jDictionary.initProxy();
  478.             applyButton.setEnabled(false);
  479.         }
  480.     }
  481.  
  482.  
  483.     //this will perform some auto save like stuff
  484.     //(if user forget to click the 'Apply' button)
  485.     //void pluginManager_pluginSelected(PluginSelectionEvent e) {
  486.     //    if(!changesSaved)
  487.     //        if(savePrefs()) {
  488.     //            jDictionary.initProxy();
  489.     //            applyButton.setEnabled(false);
  490.     //        }
  491.     //}
  492.  
  493.  
  494.     boolean savePrefs() {
  495.         prefs.CheckingForNews = newsCheckBox.isSelected();
  496.         prefs.CheckingForUpgrade = upgradeCheckBox.isSelected();
  497.  
  498.         if(validateNetworkSectionTextFileds()) {
  499.             if(typeComboBox.getSelectedItem().equals(httpType)) {
  500.                 prefs.usingHttpProxy = true;
  501.                 prefs.usingSocksProxy = false;
  502.                 saveNetworkTextFields(httpType);
  503.             }
  504.             if(typeComboBox.getSelectedItem().equals(socksType)) {
  505.                 prefs.usingSocksProxy = true;
  506.                 prefs.usingHttpProxy = false;
  507.                 saveNetworkTextFields(socksType);
  508.             }
  509.             if(!proxyCheckBox.isSelected()) {
  510.                 prefs.usingSocksProxy = false;
  511.                 prefs.usingHttpProxy = false;
  512.             }
  513.             prefs.usingHttpProxyLogin = usingHttpProxyLogin;
  514.             prefs.usingSocksProxyLogin = usingSocksProxyLogin;
  515.             prefs.httpProxyServer = httpServer;
  516.             prefs.httpProxyPort = httpPort;
  517.             prefs.httpProxyLogin = httpLogin;
  518.             prefs.httpProxyPassword = httpPassword;
  519.             prefs.socksProxyServer = socksServer;
  520.             prefs.socksProxyPort = socksPort;
  521.             prefs.socksProxyLogin = socksLogin;
  522.             prefs.socksProxyPassword = socksPassword;
  523.             changesSaved = true;
  524.             return true;
  525.         }
  526.         return false;
  527.     }
  528.  
  529.  
  530.     void updateNetworkSection() {
  531.         if(proxyCheckBox.isSelected()) {
  532.             typeComboBox.setEnabled(true);
  533.             typeLabel.setEnabled(true);
  534.             portTextField.setEnabled(true);
  535.             serverTextField.setEnabled(true);
  536.             serverLabel.setEnabled(true);
  537.             portLabel.setEnabled(true);
  538.             authCheckBox.setEnabled(true);
  539.  
  540.             if((usingHttpProxyLogin && typeComboBox.getSelectedItem().equals(httpType)) || usingSocksProxyLogin && typeComboBox.getSelectedItem().equals(socksType)) {
  541.                 if(!authCheckBox.isSelected())
  542.                     authCheckBox.setSelected(true);
  543.                 loginTextField.setEnabled(true);
  544.                 passwordField.setEnabled(true);
  545.                 loginLabel.setEnabled(true);
  546.                 passwordLabel.setEnabled(true);
  547.             }
  548.             else {
  549.                 if(authCheckBox.isSelected())
  550.                     authCheckBox.setSelected(false);
  551.                 loginTextField.setEnabled(false);
  552.                 passwordField.setEnabled(false);
  553.                 loginLabel.setEnabled(false);
  554.                 passwordLabel.setEnabled(false);
  555.             }
  556.         }
  557.         else {
  558.             typeComboBox.setEnabled(false);
  559.             typeLabel.setEnabled(false);
  560.             portTextField.setEnabled(false);
  561.             serverTextField.setEnabled(false);
  562.             serverLabel.setEnabled(false);
  563.             portLabel.setEnabled(false);
  564.             authCheckBox.setEnabled(false);
  565.             loginTextField.setEnabled(false);
  566.             passwordField.setEnabled(false);
  567.             loginLabel.setEnabled(false);
  568.             passwordLabel.setEnabled(false);
  569.         }
  570.     }
  571.  
  572.  
  573.     void updateNetworkSectionTextFields() {
  574.  
  575.         if(shownType.equals(typeComboBox.getSelectedItem())) {
  576.             return;
  577.         }
  578.         else {
  579.             shownType = (String)typeComboBox.getSelectedItem();
  580.             if(shownType.equals(httpType))
  581.                 this.saveNetworkTextFields(socksType);
  582.             if(shownType.equals(socksType))
  583.                 this.saveNetworkTextFields(httpType);
  584.             this.fillupNetworkTextFields();
  585.         }
  586.     }
  587.  
  588.  
  589.     boolean validateNetworkSectionTextFileds() {
  590.         boolean approved = true;
  591.  
  592.         if(proxyCheckBox.isSelected()) {
  593.             if(serverTextField.getText().length() == 0 && portTextField.getText().length() == 0)
  594.                 proxyCheckBox.setSelected(false);
  595.             else {
  596.                 if(serverTextField.getText().length() == 0) {
  597.                     approved = false;
  598.                     highLightTextField(serverTextField);
  599.                 }
  600.                 if(portTextField.getText().length() > 0) {
  601.                     RE regexp = null;
  602.                     try {
  603.                         regexp = new RE("^[0-9]+$");
  604.                     }
  605.                     catch(org.apache.regexp.RESyntaxException e) {}
  606.                     if(!regexp.match(portTextField.getText())) {
  607.                         approved = false;
  608.                         highLightTextField(portTextField);
  609.                     }
  610.                 }
  611.                 else {
  612.                     if(typeComboBox.getSelectedItem().equals(httpType))
  613.                         portTextField.setText("80");
  614.                     if(typeComboBox.getSelectedItem().equals(socksType))
  615.                         portTextField.setText("1080");
  616.                 }
  617.             }
  618.         }
  619.  
  620.         if(authCheckBox.isSelected()) {
  621.             if(loginTextField.getText().length() == 0 && passwordField.getPassword().length == 0)
  622.                 this.authCheckBox.setSelected(false);
  623.             else {
  624.                 if(loginTextField.getText().length() == 0) {
  625.                     approved = false;
  626.                     highLightTextField(loginTextField);
  627.                 }
  628.                 if(passwordField.getPassword().length == 0) {
  629.                     approved = false;
  630.                     highLightTextField(passwordField);
  631.                 }
  632.             }
  633.         }
  634.     return approved;
  635.     }
  636.  
  637.  
  638.     void fillupNetworkTextFields() {
  639.         if(typeComboBox.getSelectedItem().equals(httpType)) {
  640.                 serverTextField.setText(httpServer);
  641.                 portTextField.setText(httpPort);
  642.                 loginTextField.setText(httpLogin);
  643.                 passwordField.setText(new String(httpPassword));
  644.            }
  645.            if(typeComboBox.getSelectedItem().equals(socksType)) {
  646.                serverTextField.setText(socksServer);
  647.                portTextField.setText(socksPort);
  648.                loginTextField.setText(socksLogin);
  649.                passwordField.setText(new String(socksPassword));
  650.            }
  651.     }
  652.  
  653.  
  654.     void saveNetworkTextFields(String type) {
  655.         if(type.equals(httpType)) {
  656.             httpServer = serverTextField.getText();
  657.             httpPort = portTextField.getText();
  658.             httpLogin = loginTextField.getText();
  659.             httpPassword = passwordField.getPassword();
  660.         }
  661.         if(type.equals(socksType)) {
  662.             socksServer = serverTextField.getText();
  663.             socksPort = portTextField.getText();
  664.             socksLogin = loginTextField.getText();
  665.             socksPassword = passwordField.getPassword();
  666.         }
  667.     }
  668.  
  669.  
  670.     void updateStartupSection() {
  671.         if(prefs.CheckingForNews)
  672.             newsCheckBox.setSelected(true);
  673.         else
  674.             newsCheckBox.setSelected(false);
  675.         if(prefs.CheckingForUpgrade)
  676.             upgradeCheckBox.setSelected(true);
  677.         else
  678.             upgradeCheckBox.setSelected(false);
  679.     }
  680.  
  681.  
  682.     void highLightTextField(final JTextField textField) {
  683.         if(textField.getBackground().equals(highLightColor))
  684.             return;
  685.         final Color originalColor = textField.getBackground();
  686.         new Thread() {
  687.             public void run() {
  688.                 textField.setBackground(highLightColor);
  689.                 try {
  690.                     sleep(1500);
  691.                 }
  692.                 catch(java.lang.InterruptedException e) {}
  693.                 textField.setBackground(originalColor);
  694.             }
  695.         }.start();
  696.     }
  697. }